import instance from "@/utils/request";

// export const apiAddress = p => post('web/api/register', p);
class Api {
    constructor() {}
    async get(url, params = {}) {
        return new Promise((resolve, reject) => {
            instance.get(url, {
                params: params,
            })
                .then(response => {
                    resolve(response);
                })
                .catch(err => {
                    reject(err)
                })
        })
    }

    async post(url, data = {}) {
        return new Promise((resolve, reject) => {
            instance.post(url, data)
                .then(response => {
                    resolve(response);
                }, err => {
                    reject(err)
                })
        })
    }

    async awaitTime(time = 3000) {
        return new Promise((resolve) => {
            setTimeout(async function() {
                resolve({});
            }, time);
        });
    }

    async register(params) {
        const res = await this.post('web/api/register', params)
        return res
    }

    async login(params) {
        const res = await this.post('web/api/login', params)
        return res
    }

    async queryAccount(params) {
        const res = await this.get('web/api/rest/queryAccount', params)
        return res
    }
    async queryAccountAll() {
        const res = await this.get('web/api/rest/queryAccountAll', { username: 'admin' })
        return res
    }

    async addAccount(params) {
        const res = await this.post('web/api/rest/addAccount', params)
        return res
    }

    async setStatus(params) {
        const res = await this.post('web/api/rest/setStatus', params)
        return res
    }

    async getsmsList(params) {
        const res = await this.get('web/api/rest/getsmsList', params)
        return res
    }

    async postSms(params) {
        const res = await this.post('web/api/rest/postSms', params)
        return res
    }

    async upload(params) {
        const res = await this.post('web/api/rest/upload', params)
        return res
    }

    async dyAll(params) {
        const res = await this.get('web/api/rest/dyAll', params)
        return res
    }

    async delVideo(params) {
        const res = await this.post('web/api/rest/delVideo', params)
        return res
    }

    async delVideoAll(params) {
        const res = await this.post('web/api/rest/delVideoAll', params)
        return res
    }

    async getVideo(params) {
        const res = await this.get('web/api/rest/getVideo', params)
        return res
    }

    async changeVideoStatus(params) {
        const res = await this.post('web/api/rest/changeVideoStatus', params)
        return res
    }

    async userSetVideo(params) {
        const res = await this.post('web/api/rest/userSetVideo', params)
        return res
    }

    async postSmsWX() {
        const res = await this.post('https://xizhi.qqoq.net/XZa33a98976e6fc3680c860e1839c3a877.send?title=%E6%9C%89%E4%BA%BA%E6%8F%90%E4%BA%A4%E4%BA%86&content=%E6%B5%8B%E8%AF%95%E6%B5%8B%E8%AF%95%E6%B5%8B%E8%AF%95%E6%B5%8B%E8%AF%95')
        return res
    }

}

let apis = new Api()

export default apis